package com.shujia.window

import org.apache.flink.api.scala._
import org.apache.flink.streaming.api.scala.StreamExecutionEnvironment
import org.apache.flink.streaming.api.windowing.assigners.ProcessingTimeSessionWindows
import org.apache.flink.streaming.api.windowing.time.Time

object Demo3CountWindow {
  def main(args: Array[String]): Unit = {

    val env = StreamExecutionEnvironment.getExecutionEnvironment
    env.setParallelism(1)
    val ds = env.socketTextStream("node1", 8888)

    ds
      .flatMap(_.split(","))
      .map(w => (w, 1))
      .keyBy(_._1)


      //当达到一定数量之后出发窗口
      .countWindow(10)

      .reduce((x, y) => (x._1, x._2 + y._2))
      .print()

    env.execute()


  }
}
